package com.guo.adapterPattern;

import com.guo.adapterPattern.player.AdvancedMediaPlayer;
import com.guo.adapterPattern.player.Mp4Player;
import com.guo.adapterPattern.player.VlcPlayer;

/**
 * @Author 过俊文
 * @Description 创建实现了 MediaPlayer 接口的适配器类
 * @Date 2021-02-06
 **/

public class MediaAdapter implements MediaPlayer {

    AdvancedMediaPlayer advancedMusicPlayer;

    public MediaAdapter(String audioType) {
        if (audioType.equalsIgnoreCase("vlc")) {
            advancedMusicPlayer = new VlcPlayer();
        } else if (audioType.equalsIgnoreCase("mp4")) {
            advancedMusicPlayer = new Mp4Player();
        }
    }

    @Override
    public void play(String audioType, String fileName) {
        if (audioType.equalsIgnoreCase("vlc")) {
            advancedMusicPlayer.playVlc(fileName);
        } else if (audioType.equalsIgnoreCase("mp4")) {
            advancedMusicPlayer.playMp4(fileName);
        }
    }
}
